package com.qing.design.patterns.strategy.example.strategies;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * 使用信用卡支付
 */
public class PayByCreditCard implements PayStrategy{


	private final BufferedReader READER=new BufferedReader(new InputStreamReader(System.in));


	private CreditCard card;


	@Override
	public boolean pay(int paymentAmount) {
		if(cardIsPresent()){
			System.out.println("用户使用银行卡支付"+paymentAmount);
			card.setAmount(card.getAmount()-paymentAmount);
			return  true;
		}
		return false;
	}

	@Override
	public void collectPaymentDetails() {
		try {
			System.out.println("请输入银行卡号");
			String number=READER.readLine();
			System.out.println("输入卡的到期日期mm/yy");

			String date= READER.readLine();;
			System.out.println("输入CVV代码：");
			String cvv=READER.readLine();
			card=new CreditCard(number,date,cvv);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private boolean cardIsPresent(){
		return  card!=null;
	}
}
